﻿Public Class frmChronometre
    Dim startRec As Image = My.Resources.Images.demarrer
    Dim stopRec As Image = My.Resources.Images.arreter
    Dim bChronoActif As Boolean

    Private Sub btnDemarrer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDemarrer.Click
        If bChronoActif = False Then

            'Affiche l'heure au moment du clik sur btnStop sur lblTempsDepart
            lblTempsDepart.Text = TimeOfDay
            lblTempsArrive.Text = Nothing

            'Affiche btnStop et masque btn Demarrer
            Me.btnDemarrer.Image = stopRec
            bChronoActif = True
        Else
            'Affiche l'heure au moment du clik sur btnStop sur lblTempsArrive
            lblTempsArrive.Text = TimeOfDay

            'Déclaration des variable 
            'TimeSpan est un ecart de temps
            Dim TempsDeDepart As New System.DateTime()
            Dim TempsDArrive As New System.DateTime()
            Dim TempsEcoule As New TimeSpan()

            TempsDeDepart = lblTempsDepart.Text
            TempsDArrive = lblTempsArrive.Text

            'Subtract pertmet de soustraire 2 dates ou temps
            TempsEcoule = TempsDArrive.Subtract(TempsDeDepart)

            ' conversion format heure
            Dim s As String = TempsEcoule.ToString
            s = Replace(s, ":", " h ", 1, 1)
            s = Replace(s, ":", " min ", 1, 1)
            s &= " s"

            lblTempsEcoule.Text = s

            'Masque btnStop et affiche btnDemarrer
            Me.btnDemarrer.Image = startRec
            bChronoActif = False
        End If
    End Sub

    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        'Affiche l'heure au moment du clik sur btnStop sur lblTempsArrive
        lblTempsArrive.Text = TimeOfDay

        'Déclaration des variable 
        'TimeSpan est un ecart de temps
        Dim TempsDeDepart As New System.DateTime()
        Dim TempsDArrive As New System.DateTime()
        Dim TempsEcoule As New TimeSpan()

        TempsDeDepart = lblTempsDepart.Text
        TempsDArrive = lblTempsArrive.Text

        'Subtract pertmet de soustraire 2 dates ou temps
        TempsEcoule = TempsDArrive.Subtract(TempsDeDepart)

        ' conversion format heure
        Dim s As String = TempsEcoule.ToString
        s = Replace(s, ":", " h ", 1, 1)
        s = Replace(s, ":", " min ", 1, 1)
        s &= " s"

        lblTempsEcoule.Text = s

        'Masque btnStop et affiche btnDemarrer
     
    End Sub


    Private Sub tmrHeureSysteme_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrHeureSysteme.Tick
        lblHeureSysteme.Text = TimeOfDay
    End Sub


    Private Sub frmChronometre_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblTempsDepart.Text = ""
        bChronoActif = False
        Me.btnDemarrer.Image = startRec
    End Sub


    Private Sub btnRetourMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRetourMenu.Click
        Me.Hide()
        FormMain.Show()
    End Sub


    Private Sub BtnRetour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRetour.Click
        frmNavigationTools.Show()
        Me.Hide()
    End Sub

End Class
